// pages/channel/addMember/addMember.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone: '',
    userInfo: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  // 输入手机号码
  phoneInput(e){
    var phone = e.detail.value;
    this.setData({
      phone: phone
    })
    this.searchInfo(phone);
  },
  // 根据手机号拿用户
  searchInfo(phone){
    var that = this;
    app.ajax({
      url: 'User/User/getUserInfo',
      data: {
        key: phone
      },
      success: function (res) {
        if (res.data.code == 1000) {
          that.setData({
            userInfo: res.data.data
          })
        }
      }
    })
  },
  // 提交
  submit() {
    var that = this;
    app.ajax({
      url: 'User/Channel/addPromoter',
      data: {
        telphone: that.data.userInfo.telphone,
        name: that.data.userInfo.username,
        account: that.data.userInfo.account
      },
      success: function (res) {
        if (res.data.code == 1000) {
          app.showToast('添加成功', "none", 2000, function () { });
          wx.navigateBack();
        }else{
          app.showToast(res.data.message, "none", 2000, function () { });
        }
      }
    })
  },
})